﻿using System.Collections.Generic;

using Gonte.Reflection;

namespace Gonte.Workflow.Tasks
{
    /// <summary>
    /// Retrieves the accessor to an object
    /// </summary>
    public abstract class GetAccessor
        : GetInstance
    {
        protected const string Data = "Data";

        #region ITask Members

        public override TaskResult Execute(TaskContext context)
        {
            TaskResult result = base.Execute(context);
            object data = result.Value;

            result = new TaskResult();
            result.Value = TypeAccessor.GetTypeAccessor(data.GetType());
            result.AditionalValues = new Dictionary<string, object>(1);
            result.AditionalValues.Add(Data, data);

            return result;
        }

        #endregion

        #region Properties

        /// <summary>
        /// The name of the property of the object to access
        /// </summary>
        public string Property
        {
            get { return _property; }
            set { _property = value; }
        }

        #endregion

        #region Fields

        protected string _property;

        #endregion
    }
}
